package com.briup.cms.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.cms.bean.basic.Slideshow;
import com.briup.cms.service.ISlideshowService;
import com.briup.cms.util.Result;
import com.briup.cms.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lining
 * @since 2024-09-10
 */
@Api(tags = "轮播图模块")
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {
    @Autowired
    private ISlideshowService slideshowService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "desc",value = "描述信息",required = false),
            @ApiImplicitParam(name = "pageNum",value = "当前页",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页数量",required = true),
            @ApiImplicitParam(name = "status",value = "状态值",required = false)
    })
    @ApiOperation("条件多分页查询轮播图")
    @GetMapping("/query")
    public Result findByQuery(String desc, @RequestParam Integer pageNum,@RequestParam Integer pageSize, String status){
        Page<Slideshow> page = slideshowService.findByPage(desc, pageNum, pageSize, status);
        return ResultUtil.success(page);
    }

    @ApiOperation("查询所有可用的轮播图")
    @GetMapping("/queryAllEnable")
    public Result findAll(){
        return ResultUtil.success(slideshowService.findAll());
    }

    @ApiOperation("根据id查询轮播图信息")
    @ApiImplicitParam(name = "id",value = "轮播图id",required = true)
    @GetMapping("/queryById/{id}")
    public Result findById(@PathVariable Integer id){
        return ResultUtil.success(slideshowService.findById(id));
    }

    @ApiOperation("根据编号删除轮播图")
    @ApiImplicitParam(name = "ids",value = "轮播图id",required = true)
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result deleteByIds(@PathVariable String ids){
        slideshowService.deleteByIds(ids);
        return ResultUtil.success();
    }

    @ApiOperation("新增或更新轮播图")
    @ApiImplicitParam(name = "status",allowableValues = "启用,禁用",defaultValue = "启用")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(String description,Integer id,String status,String url){
        slideshowService.saveOrUpdate(description,id,status,url);
        return  ResultUtil.success();
    }

}
